package com.lqian.demo01;

import com.lqian.utils.SleepHelper;

/**
 * 设标志位是否能够把synchronized修饰的一个正在竞争锁的对象，给打断？
 */
public class Interrupt_and_Synchronized {
    private static final Object o = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (o){
                SleepHelper.sleepSeconds(10);
            }
        });
        t1.start();
        SleepHelper.sleepSeconds(1);

        Thread t2 = new Thread(()->{
            synchronized (o){
                System.out.println("i got it!!");
            }
            // synchronized锁竞争的这个过程，是不可能被interrupt给打断干扰到的
            System.out.println("t2 end..");
        });
        t2.start();

        SleepHelper.sleepSeconds(1);
        t2.interrupt();
    }
}
